---
title: "Reference: LangSmithExporter | Observability"
description: LangSmith exporter for Tracing
---

import PropertiesTable from "@site/src/components/PropertiesTable";

# LangSmithExporter

Sends Tracing data to LangSmith for observability.

## Constructor

```typescript
new LangSmithExporter(config: LangSmithExporterConfig)
```

## LangSmithExporterConfig

```typescript
interface LangSmithExporterConfig extends ClientConfig, BaseExporterConfig {
  client?: Client;
  projectName?: string;
}
```

Extends both `ClientConfig` (from LangSmith SDK) and `BaseExporterConfig`:
- From `BaseExporterConfig`: `logger?: IMastraLogger`, `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'`
- From `ClientConfig`: `apiKey`, `apiUrl`, `callerOptions`, `hideInputs`, `hideOutputs`, etc.

<PropertiesTable
  props={[
    {
      name: "apiKey",
      type: "string",
      description: "LangSmith API key. Defaults to LANGSMITH_API_KEY env var.",
      required: false,
    },
    {
      name: "projectName",
      type: "string",
      description: "The LangSmith project to send traces to. Overrides LANGCHAIN_PROJECT env var. Defaults to 'default'.",
      required: false,
    },
    {
      name: "apiUrl",
      type: "string",
      description: "LangSmith API URL",
      required: false,
    },
    {
      name: "callerOptions",
      type: "object",
      description: "HTTP client configuration options",
      required: false,
    },
    {
      name: "hideInputs",
      type: "boolean",
      description: "Hide input data in the LangSmith UI",
      required: false,
    },
    {
      name: "hideOutputs",
      type: "boolean",
      description: "Hide output data in the LangSmith UI",
      required: false,
    },
    {
      name: "logLevel",
      type: "'debug' | 'info' | 'warn' | 'error'",
      description: "Logger level (default: 'warn')",
      required: false,
    },
    {
      name: "client",
      type: "Client",
      description: "Pre-configured LangSmith client instance",
      required: false,
    },
  ]}
/>

## Methods

### exportTracingEvent

```typescript
async exportTracingEvent(event: TracingEvent): Promise<void>
```

Exports a tracing event to LangSmith.

### shutdown

```typescript
async shutdown(): Promise<void>
```

Ends all active spans and clears the trace map.

## Usage

```typescript
import { LangSmithExporter } from "@mastra/langsmith";

const exporter = new LangSmithExporter({
  apiKey: process.env.LANGSMITH_API_KEY,
  projectName: "my-project", // Optional: specify which project to send traces to
  apiUrl: "https://api.smith.langchain.com",
  logLevel: "info",
});
```

## Environment Variables

| Variable | Description |
|----------|-------------|
| `LANGSMITH_API_KEY` | Your LangSmith API key |
| `LANGCHAIN_PROJECT` | Default project name for traces (used if `projectName` not specified) |
| `LANGSMITH_BASE_URL` | API URL for self-hosted instances |

## Span Type Mapping

| Span Type       | LangSmith Type |
| ------------------ | -------------- |
| `MODEL_GENERATION` | `llm`          |
| `MODEL_CHUNK`      | `llm`          |
| `TOOL_CALL`        | `tool`         |
| `MCP_TOOL_CALL`    | `tool`         |
| All others         | `chain`        |
